/*
* Copyright 2004 Christopher M. Bouzek 
*/

using System;

namespace SMS.SMPPClient.PDU.Incoming
{
	/// <summary>
	/// Defines the submit_sm response from the SMSC.
	/// </summary>

	public class SMPPSubmitSMResponse : SMPPResponse
	{
		private string _MessageID;
		private byte[] _ResponseAfterMsgID;

		/// <summary>
		/// The message ID (SMSC-assigned) of the submitted message.
		/// </summary>
		public string MessageID
		{
			get
			{
				return _MessageID;
			}
		}

		/// <summary>
		/// Accessor for the submit_multi to get at the response after the message ID.
		/// This is, in essence, set only after DecodeSMSCResponse() in this base class
		/// is called.
		/// </summary>
		protected byte[] ResponseAfterMsgID
		{
			get
			{
				return _ResponseAfterMsgID;
			}
		}

		/// <summary>
		/// Creates a submit_sm response PDU.
		/// </summary>
		/// <param name="response">The byte response from the
		/// SMSC.</param>
		public SMPPSubmitSMResponse( byte[] response ) : base( response )
		{
			DecodeSMSCResponse( );
		}

		/// <summary>
		/// Decodes the submit response from the SMSC.
		/// </summary>
		protected override void DecodeSMSCResponse( )
		{
			DecodeNonTLV( );
			//fill the TLV table if applicable
			tlvTable.TranslateTLVDataIntoTable( _ResponseAfterMsgID );
		}

		/// <summary>
		/// Decodes the non-TLV bytes.  Needed for the submit_multi_resp.
		/// </summary>
		protected void DecodeNonTLV( )
		{
			//header
			byte[] remainder = ResponseAfterHeader;
			_MessageID = SMPPResponse.GetStringFromBody( ref remainder );
			_ResponseAfterMsgID = remainder;
		}
	}
}
